#!/bin/bash

set -e

cd ${SRCDIR}/chipsec

# Point chipsec to the image's kernel otherwise it will try to locate it based
# on the host kernel version.
KSRC=$(find /lib/modules -maxdepth 2 -name build)
export KSRC

python3 setup.py build build_ext install --root $DESTDIR/

# Install UEFI version as well
mkdir -p ${DESTDIR}/efi
unzip "__install__/UEFI/chipsec_py368_uefi_x64.zip" -d "${DESTDIR}/efi"
cp /usr/share/edk2-shell/x64/Shell.efi ${DESTDIR}/efi/EFI/Tools/
# Todo fixme
mkdir -p "${DESTDIR}/efi/chipsec"
cp -r *.py chipsec/ chipsec_tools/ "${DESTDIR}/efi/chipsec"

